//Program by:
//Ben Schmidt - bjs778 - 11054018
//Mike Nimeck - mfn028 - 11053045
//Jeff Huang - jlh105 - 11050226
//
//Fully implemented by hand, but OpenGL SuperBible example
//used heavily as reference

#version 330

// Model-view-projection matrix
uniform mat4 mvp;
uniform int base_size;

// Instanced attributes
layout (location = 0) in vec3 instance_position;

// Output color from the vertex shader
flat out vec4 vs_color;

void main(void)
{
    // Rotate the airplane geometry into the correct orientation and then
    // offset by position within the flock
    vec4 pos = vec4(instance_position, 1.0);
    
    gl_PointSize = instance_position.z + base_size;
    
    // Calculate a color based in instance index (evey plane gets a new color)
    float r = float((gl_InstanceID * 37 & 0xF) + 5) / 20.0;
    float g = float(((gl_InstanceID * 73 >> 4) & 0xF) + 5) / 20.0;
    float b = float(((gl_InstanceID * 327 >> 8) & 0xF) + 5) / 20.0;
    vs_color = vec4(r, g, b, 1.0);
    
    // Output position
    gl_Position = mvp * pos;
}
